#include "lolevel.h"
#include "platform.h"
#include "core.h"
#include "conf.h"

static long *nrflag = (long*)0x9B40;

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) capt_seq_task() {
 asm volatile (
                 "STMFD   SP!, {R3-R9,LR}\n"
                 "LDR     R6, =0x5584\n"
                 "LDR     R4, =0x1BE24\n"
                 "MOV     R9, #1\n"
                 "MOV     R7, #0\n"
 "loc_FF868BAC:\n"
                 "LDR     R0, [R6,#0x14]\n"
                 "MOV     R2, #0\n"
                 "MOV     R1, SP\n"
                 "BL      sub_FF8274FC\n"
                 "TST     R0, #1\n"
                 "BEQ     loc_FF868BD8\n"
                 "LDR     R1, =0x539\n"
                 "LDR     R0, =0xFF86833C\n"
                 "BL      sub_FF81B1CC\n"
                 "BL      sub_FF81B184\n"
                 "LDMFD   SP!, {R3-R9,PC}\n"
 "loc_FF868BD8:\n"
                 "LDR     R0, [SP]\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x24\n"
                 "ADDLS   PC, PC, R1,LSL#2\n"
                 "B       loc_FF868EB4\n"
 "loc_FF868BEC:\n"
                 "B       loc_FF868C80\n"
 "loc_FF868BF0:\n"
                 "B       loc_FF868CEC\n"
 "loc_FF868BF4:\n"
                 "B       loc_FF868CF4\n"
 "loc_FF868BF8:\n"
                 "B       loc_FF868D18\n"
 "loc_FF868BFC:\n"
                 "B       loc_FF868D0C\n"
 "loc_FF868C00:\n"
                 "B       loc_FF868D20\n"
 "loc_FF868C04:\n"
                 "B       loc_FF868D28\n"
 "loc_FF868C08:\n"
                 "B       loc_FF868D30\n"
 "loc_FF868C0C:\n"
                 "B       loc_FF868D88\n"
 "loc_FF868C10:\n"
                 "B       loc_FF868DB0\n"
 "loc_FF868C14:\n"
                 "B       loc_FF868D94\n"
 "loc_FF868C18:\n"
                 "B       loc_FF868DA0\n"
 "loc_FF868C1C:\n"
                 "B       loc_FF868DA8\n"
 "loc_FF868C20:\n"
                 "B       loc_FF868DB8\n"
 "loc_FF868C24:\n"
                 "B       loc_FF868DC0\n"
 "loc_FF868C28:\n"
                 "B       loc_FF868DC8\n"
 "loc_FF868C2C:\n"
                 "B       loc_FF868DD0\n"
 "loc_FF868C30:\n"
                 "B       loc_FF868DD8\n"
 "loc_FF868C34:\n"
                 "B       loc_FF868DE0\n"
 "loc_FF868C38:\n"
                 "B       loc_FF868DE8\n"
 "loc_FF868C3C:\n"
                 "B       loc_FF868DF0\n"
 "loc_FF868C40:\n"
                 "B       loc_FF868DF8\n"
 "loc_FF868C44:\n"
                 "B       loc_FF868E00\n"
 "loc_FF868C48:\n"
                 "B       loc_FF868E08\n"
 "loc_FF868C4C:\n"
                 "B       loc_FF868E10\n"
 "loc_FF868C50:\n"
                 "B       loc_FF868E1C\n"
 "loc_FF868C54:\n"
                 "B       loc_FF868E24\n"
 "loc_FF868C58:\n"
                 "B       loc_FF868E30\n"
 "loc_FF868C5C:\n"
                 "B       loc_FF868E38\n"
 "loc_FF868C60:\n"
                 "B       loc_FF868E68\n"
 "loc_FF868C64:\n"
                 "B       loc_FF868E70\n"
 "loc_FF868C68:\n"
                 "B       loc_FF868E78\n"
 "loc_FF868C6C:\n"
                 "B       loc_FF868E80\n"
 "loc_FF868C70:\n"
                 "B       loc_FF868E88\n"
 "loc_FF868C74:\n"
                 "B       loc_FF868E90\n"
 "loc_FF868C78:\n"
                 "B       loc_FF868E9C\n"
 "loc_FF868C7C:\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868C80:\n"
                 "BL      sub_FF8694C0\n"
                 "BL      shooting_expo_param_override\n"  // +
                 "BL      sub_FF866550\n"

 //  this code added to avoid some incorrect behavior if overrides are used.
 //  but it can cause some unexpected side effects. In this case, remove this code!

                 "MOV     R0, #0\n"
                 "STR     R0, [R4,#0x24]\n"  // fixes overrides  behavior at short shutter press
 	
 //  end of my code

                 "LDR     R0, [R4,#0x24]\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF868EC0\n"
                 "BL      sub_FF86800C\n"  
                 "MOV     R5, R0\n"
                 "LDR     R0, [R4,#0x24]\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF868CC8\n"
                 "MOV     R0, #0xC\n"
                 "BL      sub_FF86D150\n"
                 "TST     R0, #1\n"
                 "STRNE   R9, [R6,#4]\n"
                 "LDRNE   R0, [R5,#8]\n"
                 "ORRNE   R0, R0, #0x40000000\n"
                 "STRNE   R0, [R5,#8]\n"
                 "BNE     loc_FF868EC0\n"
 "loc_FF868CC8:\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF94C28C\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF8683EC\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF94C964_my\n"             // ----------->
                 "BL      capt_seq_hook_raw_here\n"      // +
                 "TST     R0, #1\n"
                 "STRNE   R9, [R6,#4]\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868CEC:\n"
                 "BL      sub_FF868464_my\n"             // ----------->
                 "B       loc_FF868D10\n"
 "loc_FF868CF4:\n"
                 "MOV     R0, #1\n"
                 "BL      sub_FF869734\n"
                 "LDR     R0, [R4,#0xC]\n"
                 "CMP     R0, #0\n"
                 "BLNE    sub_FF86A238\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868D0C:\n"
                 "BL      sub_FF86918C\n"
 "loc_FF868D10:\n"
                 "STR     R7, [R4,#0x24]\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868D18:\n"
                 "BL      sub_FF8694A0\n"
                 "B       loc_FF868D10\n"
 "loc_FF868D20:\n"
                 "BL      sub_FF8694A8\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868D28:\n"
                 "BL      sub_FF869624\n"
                 "B       loc_FF868D8C\n"
 "loc_FF868D30:\n"
                 "LDR     R5, [R0,#0xC]\n"
                 "BL      sub_FF8694B0\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF94B270\n"
                 "TST     R0, #1\n"
                 "MOV     R8, R0\n"
                 "BNE     loc_FF868D70\n"
                 "BL      sub_FF879868\n"
                 "STR     R0, [R5,#0x18]\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF94C820\n"
                 "MOV     R0, R5\n"
                 "BL      sub_FF94CC2C\n"
                 "MOV     R8, R0\n"
                 "LDR     R0, [R5,#0x18]\n"
                 "BL      sub_FF879A7C\n"
 "loc_FF868D70:\n"
                 "BL      sub_FF8694A0\n"
                 "MOV     R2, R5\n"
                 "MOV     R1, #9\n"
                 "MOV     R0, R8\n"
                 "BL      sub_FF866ADC\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868D88:\n"
                 "BL      sub_FF8696B4\n"
 "loc_FF868D8C:\n"
                 "BL      sub_FF866550\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868D94:\n"
                 "LDR     R0, [R4,#0x54]\n"
                 "BL      sub_FF869D4C\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DA0:\n"
                 "BL      sub_FF869FF8\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DA8:\n"
                 "BL      sub_FF86A088\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DB0:\n"
                 "BL      sub_FF8694A0\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DB8:\n"
                 "BL      sub_FF94B4B0\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DC0:\n"
                 "BL      sub_FF94B6DC\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DC8:\n"
                 "BL      sub_FF94B770\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DD0:\n"
                 "BL      sub_FF94B898\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DD8:\n"
                 "BL      sub_FF94B94C\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DE0:\n"
                 "BL      sub_FF94BDDC\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DE8:\n"
                 "BL      sub_FF94BE34\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868DF0:\n"
                 "MOV     R0, #0\n"
                 "B       loc_FF868E14\n"
 "loc_FF868DF8:\n"
                 "BL      sub_FF94BFD0\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E00:\n"
                 "BL      sub_FF94C060\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E08:\n"
                 "BL      sub_FF94C120\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E10:\n"
                 "MOV     R0, #1\n"
 "loc_FF868E14:\n"
                 "BL      sub_FF94BEA8\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E1C:\n"
                 "BL      sub_FF86996C\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E24:\n"
                 "BL      sub_FF869A0C\n"
                 "BL      sub_FF868FE8\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E30:\n"
                 "BL      sub_FF94BC04\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E38:\n"
                 "MOV     R2, #2\n"
                 "ADD     R1, R4, #0x74\n"
                 "MOV     R0, #0x6F\n"
                 "BL      sub_FF8796D8\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x61C\n"
                 "LDRNE   R0, =0xFF86833C\n"
                 "BLNE    sub_FF81B1CC\n"
                 "LDRH    R0, [R4,#0x74]\n"
                 "CMP     R0, #1\n"
                 "BLEQ    sub_FF94BBF8\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E68:\n"
                 "BL      sub_FF94BD30\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E70:\n"
                 "BL      sub_FF8682CC\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E78:\n"
                 "BL      sub_FF824960\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E80:\n"
                 "BL      sub_FF86B890\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E88:\n"
                 "BL      sub_FF86B8F8\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E90:\n"
                 "BL      sub_FF86B954\n"
                 "BL      sub_FF86B914\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868E9C:\n"
                 "MOV     R0, #1\n"
                 "BL      sub_FF94D430\n"
                 "LDRH    R0, [R4,#0xA0]\n"
                 "CMP     R0, #3\n"
                 "BLNE    sub_FF86BB10\n"
                 "B       loc_FF868EC0\n"
 "loc_FF868EB4:\n"
                 "LDR     R1, =0x65E\n"
                 "LDR     R0, =0xFF86833C\n"
                 "BL      sub_FF81B1CC\n"
 "loc_FF868EC0:\n"
                 "LDR     R0, [SP]\n"
                 "LDR     R1, [R0,#4]\n"
                 "LDR     R0, [R6,#0x10]\n"
                 "BL      sub_FF871404\n"
                 "LDR     R5, [SP]\n"
                 "LDR     R0, [R5,#8]\n"
                 "CMP     R0, #0\n"
                 "LDREQ   R1, =0x11D\n"
                 "LDREQ   R0, =0xFF86833C\n"
                 "BLEQ    sub_FF81B1CC\n"
                 "STR     R7, [R5,#8]\n"
                 "B       loc_FF868BAC\n"
 );
} 



void __attribute__((naked,noinline)) sub_FF868464_my(){ // 
 asm volatile(
                 "STMFD   SP!, {R3-R9,LR}\n"
                 "LDR     R4, [R0,#0xC]\n"
                 "LDR     R5, =0x1BE24\n"
                 "LDR     R0, [R4,#8]\n"
                 "LDR     R6, =0x820A\n"
                 "ORR     R0, R0, #1\n"
                 "STR     R0, [R4,#8]\n"
                 "LDRH    R0, [R5]\n"
                 "LDR     R8, =0x5584\n"
                 "MOV     R7, #0\n"
                 "CMP     R0, R6\n"
                 "BEQ     loc_FF868508\n"
                 "LDRH    R0, [R5,#0xA6]\n"
                 "CMP     R0, #3\n"
                 "BEQ     loc_FF868568\n"
                 "LDR     R0, [R4,#0xC]\n"
                 "CMP     R0, #1\n"
                 "BLS     loc_FF868514\n"
                 "LDRH    R0, [R5,#0xA4]\n"
                 "CMP     R0, #0\n"
                 "BNE     loc_FF868568\n"
                 "LDRH    R0, [R5,#0xA0]\n"
                 "CMP     R0, #2\n"
                 "BNE     loc_FF868520\n"
                 "BL      sub_FF869ABC\n"
                 "LDRH    R0, [R5]\n"
                 "CMP     R0, R6\n"
                 "BEQ     loc_FF868508\n"
                 "LDRH    R0, [R5,#0xA6]\n"
                 "CMP     R0, #3\n"
                 "BEQ     loc_FF868568\n"
                 "LDR     R0, [R4,#0xC]\n"
                 "CMP     R0, #1\n"
                 "BLS     loc_FF868514\n"
                 "LDRH    R0, [R5,#0xA4]\n"
                 "CMP     R0, #0\n"
                 "BNE     loc_FF868568\n"
                 "LDRH    R0, [R5,#0xA0]\n"
                 "CMP     R0, #2\n"
                 "BEQ     loc_FF86854C\n"
                 "B       loc_FF868520\n"
 "loc_FF868508:\n"
                 "LDRH    R0, [R5,#0xA6]\n"
                 "CMP     R0, #3\n"
                 "BEQ     loc_FF868568\n"
 "loc_FF868514:\n"
                 "LDRH    R0, [R5,#0xA4]\n"
                 "CMP     R0, #0\n"
                 "BNE     loc_FF868568\n"
 "loc_FF868520:\n"
                 "LDRH    R0, [R5,#0xA0]\n"
                 "CMP     R0, #1\n"
                 "BNE     loc_FF868568\n"
                 "LDRH    R0, [R5]\n"
                 "CMP     R0, R6\n"
                 "LDRNE   R0, [R4,#0xC]\n"
                 "CMPNE   R0, #1\n"
                 "BLS     loc_FF868568\n"
                 "LDR     R0, [R4,#0x10]\n"
                 "CMP     R0, #1\n"
                 "BNE     loc_FF868568\n"
 "loc_FF86854C:\n"
                 "LDR     R3, =0x24D\n"
                 "LDR     R2, =0xEA60\n"
                 "STR     R3, [SP]\n"
                 "LDR     R0, [R8,#0x10]\n"
                 "LDR     R3, =0xFF86833C\n"
                 "MOV     R1, #0x40000000\n"
                 "BL      sub_FF86D4D4\n"
 "loc_FF868568:\n"
                 "BL      sub_FF8682CC\n"
                 "LDR     R0, [R5,#0x24]\n"
                 "CMP     R0, #0\n"
                 "MOVEQ   R0, #2\n"
                 "BLEQ    sub_FF861ADC\n"
                 "BL      sub_FF8694B0\n"
                 "LDR     R0, [R5,#0x24]\n"
                 "CMP     R0, #0\n"
                 "BNE     loc_FF868620\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF94D430\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF94C28C\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF8698D4\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF94AE14\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF8685D8\n"
                 "BL      sub_FF94D470\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF94AFD8\n"
                 "TST     R0, #1\n"
                 "MOVNE   R2, R4\n"
                 "LDMNEFD SP!, {R3-R9,LR}\n"
                 "MOVNE   R1, #1\n"
                 "BNE     sub_FF866ADC\n"
                 "B       loc_FF8685FC\n"
 "loc_FF8685D8:\n"
                 "LDR     R0, [R5,#0xC]\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF8685F0\n"
                 "BL      sub_FF86A1C0\n"
                 "BL      sub_FF900298\n"
                 "BL      sub_FF863254\n"
 "loc_FF8685F0:\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF94AF0C\n"
                 "BL      sub_FF94D470\n"
 "loc_FF8685FC:\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF8683EC\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF94C820\n"
                 "BL      sub_FF94D2C0\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF94C964_my\n"             //----------->
                 "MOV     R7, R0\n"
                 "BL      capt_seq_hook_raw_here\n"      // +
                 "B       loc_FF86862C\n"
 "loc_FF868620:\n"
                 "LDR     R0, [R8,#4]\n"
                 "CMP     R0, #0\n"
                 "MOVNE   R7, #0x1D\n"
 "loc_FF86862C:\n"
                 "BL      sub_FF86B8F8\n"
                 "BL      sub_FF86B940\n"
                 "BL      sub_FF86B980\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, R7\n"
                 "BL      sub_FF866ADC\n"
                 "BL      sub_FF94CBBC\n"
                 "CMP     R0, #0\n"
                 "LDRNE   R0, [R4,#8]\n"
                 "ORRNE   R0, R0, #0x2000\n"
                 "STRNE   R0, [R4,#8]\n"
                 "LDR     R0, [R4,#0x1C]\n"
                 "CMP     R0, #0\n"
                 "BLNE    sub_FF86326C\n"
                 "LDRH    R0, [R5,#0xA6]\n"
                 "CMP     R0, #3\n"
                 "BEQ     loc_FF868690\n"
                 "LDRH    R0, [R5,#0xA4]\n"
                 "CMP     R0, #0\n"
                 "LDREQH  R0, [R5,#0xA0]\n"
                 "CMPEQ   R0, #2\n"
                 "MOVEQ   R0, R4\n"
                 "LDMEQFD SP!, {R3-R9,LR}\n"
                 "BEQ     sub_FF869B10\n"
 "loc_FF868690:\n"
                 "LDMFD   SP!, {R3-R9,PC}\n"
 );
}



void __attribute__((naked,noinline)) sub_FF94C964_my(){ // 
 asm volatile(
                 "STMFD   SP!, {R1-R7,LR}\n"
                 "MOV     R4, R0\n"
                 "BL      sub_FF94D5A0\n"
                 "MVN     R1, #0\n"
                 "BL      sub_FF871438\n"
                 "MOV     R2, #4\n"
                 "ADD     R1, SP, #4\n"
                 "MOV     R0, #0x8A\n"
                 "BL      sub_FF8796D8\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x373\n"
                 "LDRNE   R0, =0xFF94C930\n"
                 "BLNE    sub_FF81B1CC\n"
                 "LDR     R7, =0x1BEF8\n"
                 "LDR     R6, =0x1BE24\n"
                 "LDRSH   R1, [R7,#0xE]\n"
                 "LDR     R0, [R6,#0x9C]\n"
                 "BL      sub_FF90B00C\n"
                 "BL      sub_FF84E5F0\n"
                 "LDR     R3, =0x9B44\n"
                 "STRH    R0, [R4,#0x94]\n"
                 "STR     R3, [SP]\n"
                 "MOV     R1, R0\n"
                 "LDRH    R0, [R6,#0x70]\n"
                 "LDRSH   R2, [R7,#0xC]\n"
                 "SUB     R3, R3, #4\n"
                 "BL      sub_FF94DBC4\n"
                 "BL      wait_until_remote_button_is_released\n"
                 "BL      capt_seq_hook_set_nr\n"                     // +
                 "B       sub_FF94C9D0\n"                             // continue function in firmware
 );
}


/*************************************************************/
void __attribute__((naked,noinline)) exp_drv_task(){
 asm volatile(
                 "STMFD   SP!, {R4-R8,LR}\n"
                 "SUB     SP, SP, #0x20\n"
                 "LDR     R8, =0xBB8\n"
                 "LDR     R7, =0x6EE4\n"
                 "LDR     R5, =0x210F0\n"
                 "MOV     R0, #0\n"
                 "ADD     R6, SP, #0x10\n"
                 "STR     R0, [SP,#0xC]\n"
 "loc_FF8AD7EC:\n"
                 "LDR     R0, [R7,#0x20]\n"
                 "MOV     R2, #0\n"
                 "ADD     R1, SP, #0x1C\n"
                 "BL      sub_FF8274FC\n"
                 "LDR     R0, [SP,#0xC]\n"
                 "CMP     R0, #1\n"
                 "BNE     loc_FF8AD834\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R0, [R0]\n"
                 "CMP     R0, #0x13\n"
                 "CMPNE   R0, #0x14\n"
                 "CMPNE   R0, #0x15\n"
                 "BEQ     loc_FF8AD950\n"
                 "CMP     R0, #0x27\n"
                 "BEQ     loc_FF8AD928\n"
                 "ADD     R1, SP, #0xC\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF8AD740\n"
 "loc_FF8AD834:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x2C\n"
                 "BNE     loc_FF8AD864\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8AEA1C\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #1\n"
                 "BL      sub_FF871404\n"
                 "BL      sub_FF81B184\n"
                 "ADD     SP, SP, #0x20\n"
                 "LDMFD   SP!, {R4-R8,PC}\n"
 "loc_FF8AD864:\n"
                 "CMP     R1, #0x2B\n"
                 "BNE     loc_FF8AD880\n"
                 "LDR     R2, [R0,#0x88]!\n"
                 "LDR     R1, [R0,#4]\n"
                 "MOV     R0, R1\n"
                 "BLX     R2\n"
                 "B       loc_FF8ADD70\n"
 "loc_FF8AD880:\n"
                 "CMP     R1, #0x25\n"
                 "BNE     loc_FF8AD8D0\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF871438\n"
                 "LDR     R0, =0xFF8AA204\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF93B058\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R8\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF871344\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0xD36\n"
                 "BNE     loc_FF8AD914\n"
 "loc_FF8AD8BC:\n"
                 "LDR     R1, [SP,#0x1C]\n"
                 "LDR     R0, [R1,#0x8C]\n"
                 "LDR     R1, [R1,#0x88]\n"
                 "BLX     R1\n"
                 "B       loc_FF8ADD70\n"
 "loc_FF8AD8D0:\n"
                 "CMP     R1, #0x26\n"
                 "BNE     loc_FF8AD920\n"
                 "ADD     R1, SP, #0xC\n"
                 "BL      sub_FF8AD740\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF871438\n"
                 "LDR     R0, =0xFF8AA214\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF93B9E4\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R8\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF871344\n"
                 "TST     R0, #1\n"
                 "BEQ     loc_FF8AD8BC\n"
                 "MOV     R1, #0xD40\n"
 "loc_FF8AD914:\n"
                 "LDR     R0, =0xFF8AA90C\n"
                 "BL      sub_FF81B1CC\n"
                 "B       loc_FF8AD8BC\n"
 "loc_FF8AD920:\n"
                 "CMP     R1, #0x27\n"
                 "BNE     loc_FF8AD938\n"
 "loc_FF8AD928:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "ADD     R1, SP, #0xC\n"
                 "BL      sub_FF8AD740\n"
                 "B       loc_FF8AD8BC\n"
 "loc_FF8AD938:\n"
                 "CMP     R1, #0x2A\n"
                 "BNE     loc_FF8AD950\n"
                 "BL      sub_FF89D33C\n"
                 "BL      sub_FF89DFC8\n"
                 "BL      sub_FF89DB00\n"
                 "B       loc_FF8AD8BC\n"
 "loc_FF8AD950:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R4, #1\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x11\n"
                 "CMPNE   R1, #0x12\n"
                 "BNE     loc_FF8AD9C0\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R1, R0, R1,LSL#2\n"
                 "SUB     R1, R1, #8\n"
                 "LDMIA   R1, {R2-R4}\n"
                 "STMIA   R6, {R2-R4}\n"
                 "BL      sub_FF8AC2B4\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8AEDD0\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x90]\n"
                 "LDR     R2, [R0,#0x94]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "B       loc_FF8ADCB0\n"
 "loc_FF8AD9C0:\n"
                 "CMP     R1, #0x13\n"
                 "CMPNE   R1, #0x14\n"
                 "CMPNE   R1, #0x15\n"
                 "BNE     loc_FF8ADA74\n"
                 "ADD     R3, SP, #0xC\n"
                 "MOV     R2, SP\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FF8AC4FC\n"
                 "CMP     R0, #1\n"
                 "MOV     R4, R0\n"
                 "CMPNE   R4, #5\n"
                 "BNE     loc_FF8ADA10\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "LDR     R1, [R0,#0x7C]!\n"
                 "LDR     R12, [R0,#0xC]!\n"
                 "LDR     R3, [R0,#4]\n"
                 "MOV     R0, SP\n"
                 "BLX     R12\n"
                 "B       loc_FF8ADA48\n"
 "loc_FF8ADA10:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "CMP     R4, #2\n"
                 "LDR     R3, [R0,#0x8C]\n"
                 "CMPNE   R4, #6\n"
                 "BNE     loc_FF8ADA5C\n"
                 "LDR     R12, [R0,#0x88]\n"
                 "MOV     R0, SP\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #1\n"
                 "BLX     R12\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, SP\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FF8AD48C\n"
 "loc_FF8ADA48:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R2, [SP,#0xC]\n"
                 "MOV     R1, R4\n"
                 "BL      sub_FF8AD6E0\n"
                 "B       loc_FF8ADCB0\n"
 "loc_FF8ADA5C:\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R12, [R0,#0x88]\n"
                 "ADD     R0, R0, #4\n"
                 "MOV     R2, R4\n"
                 "BLX     R12\n"
                 "B       loc_FF8ADCB0\n"
 "loc_FF8ADA74:\n"
                 "CMP     R1, #0x21\n"
                 "CMPNE   R1, #0x22\n"
                 "BNE     loc_FF8ADAC0\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R1, R0, R1,LSL#2\n"
                 "SUB     R1, R1, #8\n"
                 "LDMIA   R1, {R2-R4}\n"
                 "STMIA   R6, {R2-R4}\n"
                 "BL      sub_FF8AB834\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8ABB30\n"
                 "B       loc_FF8ADCB0\n"
 "loc_FF8ADAC0:\n"
                 "ADD     R1, R0, #4\n"
                 "LDMIA   R1, {R2,R3,R12}\n"
                 "STMIA   R6, {R2,R3,R12}\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x24\n"
                 "ADDLS   PC, PC, R1,LSL#2\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADADC:\n"
                 "B       loc_FF8ADB70\n"
 "loc_FF8ADAE0:\n"
                 "B       loc_FF8ADB70\n"
 "loc_FF8ADAE4:\n"
                 "B       loc_FF8ADB78\n"
 "loc_FF8ADAE8:\n"
                 "B       loc_FF8ADB80\n"
 "loc_FF8ADAEC:\n"
                 "B       loc_FF8ADB80\n"
 "loc_FF8ADAF0:\n"
                 "B       loc_FF8ADB80\n"
 "loc_FF8ADAF4:\n"
                 "B       loc_FF8ADB70\n"
 "loc_FF8ADAF8:\n"
                 "B       loc_FF8ADB78\n"
 "loc_FF8ADAFC:\n"
                 "B       loc_FF8ADB80\n"
 "loc_FF8ADB00:\n"
                 "B       loc_FF8ADB80\n"
 "loc_FF8ADB04:\n"
                 "B       loc_FF8ADB98\n"
 "loc_FF8ADB08:\n"
                 "B       loc_FF8ADB98\n"
 "loc_FF8ADB0C:\n"
                 "B       loc_FF8ADC84\n"
 "loc_FF8ADB10:\n"
                 "B       loc_FF8ADC8C\n"
 "loc_FF8ADB14:\n"
                 "B       loc_FF8ADC8C\n"
 "loc_FF8ADB18:\n"
                 "B       loc_FF8ADC8C\n"
 "loc_FF8ADB1C:\n"
                 "B       loc_FF8ADC8C\n"
 "loc_FF8ADB20:\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB24:\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB28:\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB2C:\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB30:\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB34:\n"
                 "B       loc_FF8ADB88\n"
 "loc_FF8ADB38:\n"
                 "B       loc_FF8ADB90\n"
 "loc_FF8ADB3C:\n"
                 "B       loc_FF8ADB90\n"
 "loc_FF8ADB40:\n"
                 "B       loc_FF8ADBA4\n"
 "loc_FF8ADB44:\n"
                 "B       loc_FF8ADBA4\n"
 "loc_FF8ADB48:\n"
                 "B       loc_FF8ADBAC\n"
 "loc_FF8ADB4C:\n"
                 "B       loc_FF8ADBDC\n"
 "loc_FF8ADB50:\n"
                 "B       loc_FF8ADC0C\n"
 "loc_FF8ADB54:\n"
                 "B       loc_FF8ADC3C\n"
 "loc_FF8ADB58:\n"
                 "B       loc_FF8ADC6C\n"
 "loc_FF8ADB5C:\n"
                 "B       loc_FF8ADC6C\n"
 "loc_FF8ADB60:\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB64:\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB68:\n"
                 "B       loc_FF8ADC74\n"
 "loc_FF8ADB6C:\n"
                 "B       loc_FF8ADC7C\n"
 "loc_FF8ADB70:\n"
                 "BL      sub_FF8AA6F8\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB78:\n"
                 "BL      sub_FF8AA980\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB80:\n"
                 "BL      sub_FF8AAB84\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB88:\n"
                 "BL      sub_FF8AADEC\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB90:\n"
                 "BL      sub_FF8AAFE0\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADB98:\n"
                 "BL      sub_FF8AB248_my\n"  //------------>
                 "MOV     R4, #0\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADBA4:\n"
                 "BL      sub_FF8AB384\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADBAC:\n"
                 "LDRH    R1, [R0,#4]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R0,#0xC]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8AEA90\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADBDC:\n"
                 "LDRH    R1, [R0,#4]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R5,#8]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8AEBEC\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADC0C:\n"
                 "LDRH    R1, [R5]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R0,#6]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R5,#8]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8AEC98\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADC3C:\n"
                 "LDRH    R1, [R5]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R0,#0xC]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8AED38\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADC6C:\n"
                 "BL      sub_FF8AB5F8\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADC74:\n"
                 "BL      sub_FF8ABC34\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADC7C:\n"
                 "BL      sub_FF8ABE6C\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADC84:\n"
                 "BL      sub_FF8ABFE4\n"
                 "B       loc_FF8ADC90\n"
 "loc_FF8ADC8C:\n"
                 "BL      sub_FF8AC17C\n"
 "loc_FF8ADC90:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "CMP     R4, #1\n"
                 "BNE     loc_FF8ADCF8\n"
 "loc_FF8ADCB0:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, #0xC\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R0, R0, R1,LSL#2\n"
                 "SUB     R4, R0, #8\n"
                 "LDR     R0, =0x210F0\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FFB00004\n"
                 "LDR     R0, =0x210FC\n"
                 "MOV     R2, #0xC\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FFB00004\n"
                 "LDR     R0, =0x21108\n"
                 "MOV     R2, #0xC\n"
                 "MOV     R1, R4\n"
                 "BL      sub_FFB00004\n"
                 "B       loc_FF8ADD70\n"
 "loc_FF8ADCF8:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R0, [R0]\n"
                 "CMP     R0, #0xB\n"
                 "BNE     loc_FF8ADD40\n"
                 "MOV     R3, #0\n"
                 "STR     R3, [SP]\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF8AA500\n"
                 "MOV     R3, #0\n"
                 "STR     R3, [SP]\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #0\n"
                 "B       loc_FF8ADD6C\n"
 "loc_FF8ADD40:\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #1\n"
                 "STR     R3, [SP]\n"
                 "BL      sub_FF8AA500\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #1\n"
                 "STR     R3, [SP]\n"
 "loc_FF8ADD6C:\n"
                 "BL      sub_FF8AA640\n"
 "loc_FF8ADD70:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8AEA1C\n"
                 "B       loc_FF8AD7EC\n"
 );
}

void __attribute__((naked,noinline)) sub_FF8AB248_my(){ // 
 asm volatile(
                 "STMFD   SP!, {R4-R8,LR}\n"
                 "LDR     R7, =0x6EE4\n"
                 "MOV     R4, R0\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x3E\n"
                 "BL      sub_FF871438\n"
                 "LDRSH   R0, [R4,#4]\n"
                 "MOV     R2, #0\n"
                 "MOV     R1, #0\n"
                 "BL      sub_FF8AA288\n"
                 "MOV     R6, R0\n"
                 "LDRSH   R0, [R4,#6]\n"
                 "BL      sub_FF8AA3A0\n"
                 "LDRSH   R0, [R4,#8]\n"
                 "BL      sub_FF8AA3F8\n"
                 "LDRSH   R0, [R4,#0xA]\n"
                 "BL      sub_FF8AA450\n"
                 "LDRSH   R0, [R4,#0xC]\n"
                 "BL      sub_FF8AA4A8\n"
                 "MOV     R5, R0\n"
                 "LDR     R0, [R4]\n"
                 "LDR     R8, =0x21108\n"
                 "CMP     R0, #0xB\n"
                 "MOVEQ   R6, #0\n"
                 "MOVEQ   R5, #0\n"
                 "BEQ     loc_FF8AB2D8\n"
                 "CMP     R6, #1\n"
                 "BNE     loc_FF8AB2D8\n"
                 "LDRSH   R0, [R4,#4]\n"
                 "LDR     R1, =0xFF8AA1F4\n"
                 "MOV     R2, #2\n"
                 "BL      sub_FF93B3A0\n"
                 "STRH    R0, [R4,#4]\n"
                 "MOV     R0, #0\n"
                 "STR     R0, [R7,#0x28]\n"
                 "B       loc_FF8AB2E0\n"
 "loc_FF8AB2D8:\n"
                 "LDRH    R0, [R8]\n"
                 "STRH    R0, [R4,#4]\n"
 "loc_FF8AB2E0:\n"
                 "CMP     R5, #1\n"
                 "LDRNEH  R0, [R8,#8]\n"
                 "BNE     loc_FF8AB2FC\n"
                 "LDRSH   R0, [R4,#0xC]\n"
                 "LDR     R1, =0xFF8AA278\n"
                 "MOV     R2, #0x20\n"
                 "BL      sub_FF8AEA4C\n"
 "loc_FF8AB2FC:\n"
                 "STRH    R0, [R4,#0xC]\n"
                 "LDRSH   R0, [R4,#6]\n"
                 "BL      sub_FF89D0AC_my\n"   //------------>
                 "LDRSH   R0, [R4,#8]\n"
                 "MOV     R1, #1\n"
                 "BL      sub_FF89D7F8\n"
                 "MOV     R1, #0\n"
                 "ADD     R0, R4, #8\n"
                 "BL      sub_FF89D880\n"
                 "LDRSH   R0, [R4,#0xE]\n"
                 "BL      sub_FF8A5F14\n"
                 "LDR     R4, =0xBB8\n"
                 "CMP     R6, #1\n"
                 "BNE     loc_FF8AB354\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #2\n"
                 "BL      sub_FF871344\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x54D\n"
                 "LDRNE   R0, =0xFF8AA90C\n"
                 "BLNE    sub_FF81B1CC\n"
 "loc_FF8AB354:\n"
                 "CMP     R5, #1\n"
                 "LDMNEFD SP!, {R4-R8,PC}\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #0x20\n"
                 "BL      sub_FF871344\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x552\n"
                 "LDRNE   R0, =0xFF8AA90C\n"
                 "LDMNEFD SP!, {R4-R8,LR}\n"
                 "BNE     sub_FF81B1CC\n"
                 "LDMFD   SP!, {R4-R8,PC}\n"
 );
}

void __attribute__((naked,noinline)) sub_FF89D0AC_my(){ // 
 asm volatile(
                 "STMFD   SP!, {R4-R6,LR}\n"
                 "LDR     R5, =0x6C14\n"
                 "MOV     R4, R0\n"
                 "LDR     R0, [R5,#4]\n"
                 "CMP     R0, #1\n"
                 "MOVNE   R1, #0x140\n"
                 "LDRNE   R0, =0xFF89CEB0\n"
                 "BLNE    sub_FF81B1CC\n"
                 "CMN     R4, #0xC00\n"
                 "LDREQSH R4, [R5,#2]\n"
                 "CMN     R4, #0xC00\n"
                 "LDREQ   R1, =0x146\n"
                 "LDREQ   R0, =0xFF89CEB0\n"
                 "STRH    R4, [R5,#2]\n"
                 "BLEQ    sub_FF81B1CC\n"
                 "MOV     R0, R4\n"
           //    "BL      sub_FF9E0128\n"  // -
                 "BL      apex2us\n"  // +
                 "MOV     R4, R0\n"
           //    "BL      nullsub_228\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF8D6280\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x14B\n"
                 "LDMNEFD SP!, {R4-R6,LR}\n"
                 "LDRNE   R0, =0xFF89CEB0\n"
                 "BNE     sub_FF81B1CC\n"
                 "LDMFD   SP!, {R4-R6,PC}\n"
 );
}
